﻿using System;
using Xunit;

namespace Unity.String.Tests.Number
{
    public class FloatExtendTest
    {
        [Fact]
        public void IsFiniteTest()
        {
            double testDoubleFiniteValue = 10d;
            Assert.True(FloatExtend.IsFinite(testDoubleFiniteValue));
            double testDoubleNotFiniteValue = Math.Pow(2, 1000000000000);
            Assert.False(FloatExtend.IsFinite(testDoubleNotFiniteValue));
            
            float testFloatFiniteValue = 10f;
            Assert.True(FloatExtend.IsFinite(testFloatFiniteValue));
            float testFloatNotFiniteValue = (float) Math.Pow(2, 1000000000000);
            Assert.False(FloatExtend.IsFinite(testFloatNotFiniteValue));
        }

        [Fact]
        public void IsNegativeTest()
        {
            double testDoubleNegativeValue = -123.456d;
            Assert.True(FloatExtend.IsNegative(testDoubleNegativeValue));
            double testDoubleNotNegativeValue = 123.456d;
            Assert.False(FloatExtend.IsNegative(testDoubleNotNegativeValue));
            
            float testFloatNegativeValue = -123.456f;
            Assert.True(FloatExtend.IsNegative(testFloatNegativeValue));
            float testFloatNotNegativeValue = 123.456f;
            Assert.False(FloatExtend.IsNegative(testFloatNotNegativeValue));
        }

        [Fact]
        public void SingleToInt32BitsTest()
        {
            float testFloatValue = 123.456f;
            int funcValue = FloatExtend.SingleToInt32Bits(testFloatValue);
            Assert.Equal(1123477881, funcValue);
        }
    }
}